package ai.hou.camera.util;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.provider.MediaStore;
import android.provider.Settings;

/**
 * @author zhaoxiaolei
 * @date 2021/3/15 16:54
 */
public class IntentUtils {

    /**
     * 打开相册
     */
    public static void openAlbum(Activity activity, int requestCode) {
        Intent intentFromGallery;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            intentFromGallery = new Intent(Intent.ACTION_OPEN_DOCUMENT, null);
        } else {
            intentFromGallery = new Intent(Intent.ACTION_PICK, null);
        }
        intentFromGallery.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
        activity.startActivityForResult(intentFromGallery, requestCode);
    }

    /**
     * 去设置里的应用详情
     */
    public static void goAppDetail(Activity activity, int requestCode){
        Intent intent;
        try {
            intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            Uri uri = Uri.fromParts("package", activity.getPackageName(), null);
            intent.setData(uri);
            activity.startActivityForResult(intent, requestCode);
        } catch (Exception e) {
            intent = new Intent(Settings.ACTION_SETTINGS);
            activity.startActivityForResult(intent, requestCode);
        }
    }
}
